#include <gtest/gtest.h>
#include <cstdlib>
#include <ctime>
#include <iostream>

#include <spdlog/spdlog.h>
#include <entt/entt.hpp>

struct ACom {
  int n;
};
struct BCom {
  int n;
};

TEST(EnttMulitTest, BasicAssertion) {

  int a = 0;

  entt::registry reg;
  std::vector<entt::entity> e_arr;
  for (uint32_t i = 0; i < 10; i++) {
    auto e = reg.create();
    reg.emplace<ACom>(e, ACom{});
    reg.emplace<BCom>(e, BCom{});
    if (i < 5)
      e_arr.push_back(e);
  }
  auto group = reg.group<ACom, BCom>();

  auto start = std::clock();
  reg.view<ACom, BCom>().each([](auto e, auto& a, auto& b) {
    a.n = 1;
    b.n = 1;
  });

  SPDLOG_INFO("e_arr size: {} ", e_arr.size());
  for (auto& e : e_arr) {
    reg.destroy(e);
  }
  SPDLOG_INFO("step: 1 time: {} ms", std::clock() - start);

  // auto group = reg.group<ACom, BCom>(entt::get<ACom>);

  start = std::clock();
  group.each([](auto e, auto& a, auto& b) {
    SPDLOG_INFO("n: {} ", a.n);
    a.n = 2;
    b.n = 3;
  });
  SPDLOG_INFO("step: 1 time: {} ms", std::clock() - start);

  start = std::clock();
  for (auto [e, a, b] : group.each()) {
    SPDLOG_INFO("n: {} ", a.n);
    a.n = 2;
    b.n = 3;
  }
  SPDLOG_INFO("step: 2 time: {} ms", std::clock() - start);

  EXPECT_EQ(1, 1);
}

int main(int argc, char* argv[]) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
